﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace Common.UI.Controls
{
    public class LayoutPanel : WrapPanel
    {
        public LayoutPanel()
        {
            this.LayoutUpdated += new EventHandler(LayoutPanel_LayoutUpdated);
        }

        void LayoutPanel_LayoutUpdated(object sender, EventArgs e)
        {
            Double maxWidth = 0.0;
            foreach (var item in this.Children)
            {
                IControlWidth control = item as IControlWidth;
                if (control != null && maxWidth < control.LabelWidth)
                {
                    maxWidth = control.LabelWidth;
                }
            }

            foreach (var item in this.Children)
            {
                IControlWidth control = item as IControlWidth;
                if (control != null)
                {
                    control.LabelWidth = maxWidth;
                }
            }
        }
    }
    interface IControlWidth
    {
        double LabelWidth
        {
            get;
            set;
        }
    }
}